package Deliveries;

import java.util.Calendar;
import java.util.Date;

/**
 * Class that represents the communicator with the Deliveries System.
 * 
 * @author iSolutions Orders Team
 *
 */
public class DeliveriesComm {
	
	/**
	 * A method, which sends the Deliveries the unique identifier of a newly inserted order.
	 * and asks them to retrieve the order's details from the database and reply if they can serve the order.
	 * The Deliveries system should return the estimate Date, when the order is supposed to be delivered.
	 * If they can not serve the particular order, they return a null value for the Date parameter.
	 * Since this functionality is implemented by the deliveries system, his is just a mock class that
	 * does not confirm an order if the orderID is an even number. If the orderID is and odd number then
	 * the order is confirmed and a delivery date of (today's date+3) is returned.
	 *   
	 * @param long orderID the identifier, which uniquely specifies an order.
	 * @return Date or null.
	*/
	public Date requestOrderConfirmation(long orderID) { // deliveries should confirm that the order can be served
        System.out.println("The deliveries are sent for confirmation orderID: "+orderID);
		if (orderID % 2 == 1) { // our arbitrary implementation
			Calendar c = Calendar.getInstance();
			c.setTime(new Date());
			c.add(Calendar.DATE, 3);
			Date date = c.getTime();
		    return date; // Will always return the estimated delivery time 2-3 days from the time the order has been placed.
		}
		else {
			return  null;
		}
	}
	
}
